package com.servlet.project.service;

import com.servlet.project.entity.Activity;
import com.servlet.project.entity.Announcement;
import com.servlet.project.util.JdbcUtil;

import java.util.List;

public class ActivityService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into activity(activityname,activitydate,activitylocation,activitycontent,activityarranger) values(?,?,?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<Activity> getListAll(int page, int rows, Activity obj) {
        String sql="select * from activity where 1=1 ";
        if(obj.getActivityname()!=null&&!obj.getActivityname().equals("")){
            sql+=" and activityname like '%"+obj.getActivityname()+"%' ";
        }
        sql+=" limit "+page+","+rows;
        List<Activity> memberList= JdbcUtil.executeQuery(sql,null,Activity.class);
        return memberList;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(Activity obj) {
        String sql="select * from activity where 1=1 ";
        if(obj.getActivityname()!=null&&!obj.getActivityname().equals("")){
            sql+=" and activityname like '%"+obj.getActivityname()+"%' ";
        }
        List<Activity> memberList= JdbcUtil.executeQuery(sql,null,Activity.class);
        return memberList.size();
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update activity set activityname=?,activitydate=?,activitylocation=?,activitycontent=?,activityarranger=? where activityid=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param activityid
     * @return
     */
    public Activity getId(String activityid) {
        String sql="select * from activity where activityid="+activityid;
        List<Activity> users= JdbcUtil.executeQuery(sql,null,Activity.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from activity  where activityid=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
